import { Component, OnInit } from '@angular/core';
import {HttpService,TipService} from 'itcloud-plugin';
import { GetPathService } from '../../get-path.service';
@Component({
  selector: 'app-close-time-tip',
  templateUrl: './close-time-tip.component.html',
  styleUrls: ['./close-time-tip.component.css']
})
export class CloseTimeTipComponent implements OnInit {
  data;
  handler;
  startDate= Date.now(); //开启时间默认； 
  closeTime:any;
  constructor(
    private http:HttpService,
    private GetPathService:GetPathService,
    private tipService:TipService
  ) { }

  ngOnInit() {
  }
   //关闭时间选项；
   endDataOptions = {
    minDate: new Date(Date.now()-24*60*60*1000), // Minimal selectable date
    maxDate: new Date('2099/05/31'), // Maximal selectable date
    width: '50%'
  };

  endDateEvent(ev){
   this.closeTime = ev.date;
  }
  endFn(){
    let  paramStatus = {
        closeTime:this.timeStamp(this.closeTime),
        infoId:this.data,
        operation:0
    }
    this.http.getData({
      url: this.GetPathService.AjaxPath.bulletinServer+'/bulletin/udateStatus',
      search: paramStatus,
    }).subscribe(res => {
      if(res['returnCode']==='0000'){
          this.tipService.show({ type: 'success', title: res['returnMessage']});
        }
        this.handler();
    }, err => {this.tipService.show({ type: 'error', title: "加载失败"}); })
  }
  //时间戳转换成时间
  timeStamp(timestamp){
    let Y,M,D,h,m,s;
        let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        //var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
        h = (date.getHours() < 10 ? '0'+ date.getHours() : date.getHours()) + ':';
        m = (date.getMinutes() < 10 ? '0'+ date.getMinutes() : date.getMinutes()) + ':';
        s = (date.getSeconds()< 10 ? '0'+ date.getSeconds() : date.getSeconds());
        return Y+M+D+h+m+s;
}

}
